<?php
    if ($pagination->isCurrentFirstPage()) {
        $current_url_params = ['id' => $topic->id];
    } else {
        $current_url_params = [
            'id' => $topic->id,
            'page' => $pagination->currentPage(),
        ];
    }

    $open_graph = [
        'title' => $topic->label,
        'description' => _f('The collections about %s, on %s.', $topic->label, get_app_configuration('brand')),
        'locale' => get_current_locale(),
        'url' => url_full('topic', $current_url_params),
    ];
    if ($topic->image_filename) {
        $open_graph['image'] = url_media_full('cards', $topic->image_filename);
    }

    $this->layout('base.phtml', [
        'title' => $topic->label,
        'canonical' => url_full('topic', $current_url_params),
        'current_tab' => 'feeds',
        'open_graph' => $open_graph,
    ]);
?>

<div class="section section--longbottom">
    <?php if ($topic->image_filename): ?>
        <img
            class="section__image"
            alt=""
            src="<?= url_media('large', $topic->image_filename) ?>"
        />
    <?php endif; ?>

    <div class="section__title">
        <h1><?= protect($topic->label) ?></h1>
    </div>

    <?php if ($collections): ?>
        <div class="cards cards--centered">
            <?php foreach ($collections as $collection): ?>
                <?= $this->include('collections/_collection.phtml', [
                    'collection' => $collection,
                    'display_by' => true,
                    'display_number_links' => true,
                    'display_visibility' => false,
                ]) ?>
            <?php endforeach; ?>
        </div>

        <?= $this->include('_pagination.phtml', ['pagination' => $pagination, 'url' => url('topic', ['id' => $topic->id])]) ?>
    <?php else: ?>
        <p class="paragraph--placeholder">
            <?= _('The community didn’t publish any collection in this topic yet. Will you be the first?') ?>
        </p>
    <?php endif; ?>
</div>
